<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Stroke Server</title>
	</head>
	
	<body>
		<c:if test="${!empty serverMessage}">
			<c:out value="${serverMessage}" />
			<br />
			<hr />
		</c:if>
		<c:if test="${!empty admin}">
			Willkommen <c:out value="${admin.email} " />
			
			<form action="Server" method="POST" style="display: inline">
				<input type="hidden" name="action" value="logout">
				<input type="submit" value="Logout">
			</form>
			<br />
			<br />
			<form action="Server" method="POST" style="display: inline">
				<input type="hidden" name="action" value="start">
				<c:choose>
					<c:when test="${run}">
						<input type="submit" value="Start" disabled="disabled">
					</c:when>
					<c:otherwise>
						<input type="submit" value="Start">
					</c:otherwise>
				</c:choose>
			</form>
			<form action="Server" method="POST" style="display: inline">
				<input type="hidden" name="action" value="stop">
				<c:choose>
					<c:when test="${run}">
						<input type="submit" value="Stop">
					</c:when>
					<c:otherwise>
						<input type="submit" value="Stop" disabled="disabled">
					</c:otherwise>
				</c:choose>
			</form>
			<form action="Server" method="POST" style="display: inline">
				<input type="hidden" name="action" value="restart">
				<c:choose>
					<c:when test="${run}">
						<input type="submit" value="Restart">
					</c:when>
					<c:otherwise>
						<input type="submit" value="Restart" disabled="disabled">
					</c:otherwise>
				</c:choose>
			</form>
			<br />
	
			<br />
			<hr />
	
			<!-- ****************************************************** -->
	
			<hr />
			<br />
	
			<c:if test="${!empty dbMessage}">
				<c:out value="${dbMessage}" />
				<br />
				<hr />
			</c:if>
			<c:if test="${!empty dbError}">
				<div style="color: red;">
					<c:out value="${dbError}" />
				</div>
				<br />
				<hr />
			</c:if>
			<form action="Server" method="POST" style="display: inline">
				<input type="hidden" name="action" value="insert">
				<table>
					<tr>
						<td>Type:</td>
						<td>
							<select name="type">
								<option value=""></option>
								<option value="a">Admin</option>
								<option value="d">Doctor</option>
								<option value="p">Paramedic</option>
							</select>
						</td>
						<td>
							<c:if test="${!empty emptyType}">
								<div style="color: red;">
									<c:out value="${emptyType}" />
								</div>
							</c:if>
						</td>
					</tr>
					<tr>
						<td>Email:</td>
						<td><input type="text" name="email" /></td>
						<td>
							<c:if test="${!empty wrongEmail}">
								<div style="color: red;">
									<c:out value="${wrongEmail}" />
								</div>
							</c:if>
						</td>
					</tr>
					<tr>
						<td>Password:</td>
						<td><input type="password" name="password" /></td>
						<td>
							<c:if test="${!empty wrongPassword}">
								<div style="color: red;">
									<c:out value="${wrongPassword}" />
								</div>
							</c:if>
						</td>
					</tr>
					<tr>
						<td>Repeat Password:</td>
						<td><input type="password" name="repeatpw" /></td>
						<td>
							<c:if test="${!empty passwordsDontMatch}">
								<div style="color: red;">
									<c:out value="${passwordsDontMatch}" />
								</div>
							</c:if>
						</td>
					</tr>
				</table>
				<input type="submit" value="Insert">
			</form>
			<br />
			<br />
			<table>
				<tr>
					<th>Type</th>
					<th>Email</th>
					<th></th>
				</tr>
				<c:forEach var="user" items="${allUsers}">
					<tr>
						<td><c:out value="${user.type}" /></td>
						<td><c:out value="${user.email}" /></td>
						<td>
							<form action="Server" method="POST" style="display: inline">
								<input type="hidden" name="action" value="delete"> 
								<input type="hidden" name="id" value="${user.id}"> 
								<input type="submit" value="Delete">
							</form>
						</td>
					</tr>
				</c:forEach>
			</table>
		</c:if>
	</body>
</html>